{% include "../public/min-header.html" %}
<div class="wrapper">
	{% include "../public/breadcrumb.html" %}
	<section class="content">
       <div class="row">
       		<div class="col-xs-12">
	       	  <div class="box">
	           	<div class="box-header">
	               	<nav class="navbar navbar-default">	     
				        <div class="collapse navbar-collapse">
				          	<form class="navbar-form form-inline" action="{:Url('/Admin/linkList')}" method="post">
					          	<div class="input-group">
					          		<p>数据库中共有{{table_num}}张表，共计{{helper.bytes_to_size(total)}}</p>
					          	</div>
					            <div class="form-group pull-right">
						            <a href="javascript:void(0)" onclick="gobackup(this)" class="btn btn-primary pull-right"><i class="fa fa-eject"></i>备份</a>
					            </div>		          
				          	</form>		
				      	</div>
	    			</nav>               
	            </div>	    
	             <!-- /.box-header -->
	            <div class="box-body">	             
	           		<div class="row">
	            	<div class="col-sm-12">
	            	<form  method="post" action="">
		              	<table class="table table-bordered table-striped">
		                 	<thead>
			                   	<tr>
			                       	<th class="text-center" style="width: 2px;"><input type="checkbox" onclick="javascript:$('input[name*=backs]').prop('checked',this.checked);"></th>
				                   	<th class="sorting" tabindex="0">数据库表</th>
				                   	<th class="sorting" tabindex="0">记录条数</th>
				                   	<th class="sorting" tabindex="0">占用空间</th>
				                   	<th class="sorting" tabindex="0">编码</th>
				                   	<th class="sorting" tabindex="0">创建时间</th>
				                   	<th class="sorting" tabindex="0">说明</th>
				                   	<th class="sorting" tabindex="0">操作</th>
			                   	</tr>
		                 	</thead>
							<tbody>
							  	{% for vo in lists %}
								  	<tr>
		 							 	<td><input type="checkbox" name="backs[]" value="{{vo.Name}}"></td>
				                     	<td>{{vo.Name}}</td>
				                     	<td>{{vo.Rows}}</td>
				                     	<td>{{helper.bytes_to_size(vo.Data_length)}}</td>
				                     	<td>{{vo.Collation}}</td>
				                     	<td>{{helper.time_to_date(helper.date_to_time(vo.Create_time))}}</td>
				                     	<td>{{vo.Comment}}</td>
				                     	<td>
				                      		<a class="btn btn-success ope"  data-table="{{vo.Name}}" data-act="op">优化</a>
				                      		<a class="btn btn-info ope" data-table="{{vo.Name}}" data-act="re" >修复</a>
										</td>
				                   	</tr>
			                  	{% endfor %}
		                   	</tbody>
		                 	<tfoot>
		                 	</tfoot>
		               	</table>
		           	</form>
	               </div>
	           </div>
	          </div>
	        </div>
       	</div>
       </div>
   </section>
</div>
<script type="text/javascript">
function gobackup(obj){
	let a = [];
	let _csrf = '';
	$('input[name*=backs]').each(function(i,o){
		if($(o).is(':checked')){
			a.push($(o).val());
		}
	});
	_csrf = $('input[name="_csrf"]').val();
	if(a.length==0){
		layer.alert('请选择要备份的数据表', {icon: 2});  //alert('请选择要备份的数据表');
		return;
	}else{
		$(obj).addClass('disabled');
		$(obj).html('备份进行中...');
		$.ajax({
			type :'post',
			url : "{{helper.pathFor('adtlin')}}",
			datatype : 'json',
			data : {tables:a,_csrf},
			success : function(data){
				if(data.status==1){
					$(obj).removeClass('disabled');
					$(obj).html('备份');
					layer.alert(data.message, {icon: 1});  //alert(data.msg);
				}else{
					$(obj).removeClass('disabled');
					layer.alert(data.message, {icon: 2});  //alert(data.msg);
				}
			}
		})
	}
}

$('.ope').on('click',function() {
    const post_url = "{{helper.pathFor('adtlop')}}";
    const table = $(this).attr('data-table');
    const act = $(this).attr('data-act');
    const _csrf = "{{ ctx.csrf | safe }}";
    $.ajax({
        type: 'POST',
        url: post_url,
        data: {table, act, _csrf},
        dataType: 'JSON',
        success(result) {
            return layer.msg(result.message);
        },
    });
});
</script>
{% include "../public/main-footer.html" %}